<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/11/14 014
 * Time: 14:43
 */

namespace App\Http\Controllers;

use App\Command\GarageDoor;
use App\Command\GarageDoorUpCommand;
use App\Command\GarageDoorDownCommand;
use App\Command\Light;
use App\Command\MacroCommand;
use App\Command\RemoteControl;
use App\Command\RemoteControlWithUndo;
use App\Command\SimpleRemoteControl;
use App\Command\LightOnCommand;
use App\Command\LightOffCommand;
use App\Command\Stereo;
use App\Command\StereoOffCommand;
use App\Command\StereoOnWithCDCommand;
use Psy\Command\Command;

class CommandController
{
    public function index()
    {
        $remote = new SimpleRemoteControl();
        $light = new Light();
        $lightOn = new LightOnCommand($light);
        $lightOff = new LightOffCommand($light);

        $remote->setCommand($lightOn);
        $remote->buttonWasPressed();

        $garageDoor = new GarageDoor();
        $garageDoorUp = new GarageDoorUpCommand($garageDoor);

        $remote->setCommand($garageDoorUp);
        $remote->buttonWasPressed();


        /*------ Remote Control -------*/

        $remoteControl = new RemoteControl();
        $livingRoomLight = new Light("Living Room");
        $kitchenLight = new Light("Kitchen");
        $garageDoor = new GarageDoor("");
        $stereo = new Stereo("Living Room");

        $livingRoomLightOn = new LightOnCommand($livingRoomLight);
        $livingRoomLightOff = new LightOffCommand($livingRoomLight);
        $kitchenLightOn = new LightOnCommand($kitchenLight);
        $kitchenLightOff = new LightOffCommand($kitchenLight);

        $garageDoorUp = new GarageDoorUpCommand($garageDoor);
        $garageDoorDown = new GarageDoorDownCommand($garageDoor);

        $stereoOnWithCD = new StereoOnWithCDCommand($stereo);
        $stereoOff = new StereoOffCommand($stereo);

        $remoteControl->setCommand(0, $livingRoomLightOn, $livingRoomLightOff);
        $remoteControl->setCommand(1, $kitchenLightOn, $kitchenLightOff);
        $remoteControl->setCommand(2, $garageDoorUp, $garageDoorDown);
        $remoteControl->setCommand(3, $stereoOnWithCD, $stereoOff);

        echo $remoteControl->toString();

        $remoteControl->onButtonWasPushed(0);
        $remoteControl->offButtonWasPushed(0);
        $remoteControl->onButtonWasPushed(1);
        $remoteControl->offButtonWasPushed(1);
        $remoteControl->onButtonWasPushed(2);
        $remoteControl->offButtonWasPushed(2);
        $remoteControl->onButtonWasPushed(3);
        $remoteControl->offButtonWasPushed(3);


        /*------ Undo Remote Control -------*/

        $remoteControlWithUndo = new RemoteControlWithUndo();
        $livingRoomLight = new Light("Living Room");
        $kitchenLight = new Light("Kitchen");
        $garageDoor = new GarageDoor("");
        $stereo = new Stereo("Living Room");

        $livingRoomLightOn = new LightOnCommand($livingRoomLight);
        $livingRoomLightOff = new LightOffCommand($livingRoomLight);
        $kitchenLightOn = new LightOnCommand($kitchenLight);
        $kitchenLightOff = new LightOffCommand($kitchenLight);

        $garageDoorUp = new GarageDoorUpCommand($garageDoor);
        $garageDoorDown = new GarageDoorDownCommand($garageDoor);

        $stereoOnWithCD = new StereoOnWithCDCommand($stereo);
        $stereoOff = new StereoOffCommand($stereo);

        $remoteControlWithUndo->setCommand(0, $livingRoomLightOn, $livingRoomLightOff);

        //echo $remoteControlWithUndo->toString();

        $remoteControlWithUndo->onButtonWasPushed(0);
        $remoteControlWithUndo->offButtonWasPushed(0);

        echo $remoteControlWithUndo->toString();

        $remoteControlWithUndo->undoButtonWasPushed();
        $remoteControlWithUndo->offButtonWasPushed(0);
        $remoteControlWithUndo->onButtonWasPushed(0);

        echo $remoteControlWithUndo->toString();
        $remoteControlWithUndo->undoButtonWasPushed();

        /*------ Marco Command -------*/

        $livingRoomLight = new Light("Living Room");
        $kitchenLight = new Light("Kitchen");
        $garageDoor = new GarageDoor("");
        $stereo = new Stereo("Living Room");

        $livingRoomLightOn = new LightOnCommand($livingRoomLight);
        $livingRoomLightOff = new LightOffCommand($livingRoomLight);
        $kitchenLightOn = new LightOnCommand($kitchenLight);
        $kitchenLightOff = new LightOffCommand($kitchenLight);

        $garageDoorUp = new GarageDoorUpCommand($garageDoor);
        $garageDoorDown = new GarageDoorDownCommand($garageDoor);

        $stereoOnWithCD = new StereoOnWithCDCommand($stereo);
        $stereoOff = new StereoOffCommand($stereo);

        $partyOn = array($livingRoomLightOn, $kitchenLightOn, $garageDoorUp, $stereoOnWithCD);
        $partyOff = array($livingRoomLightOff, $kitchenLightOff, $garageDoorDown, $stereoOff);

        $partyOnMacro = new MacroCommand($partyOn);
        $partyOffMacro = new MacroCommand($partyOff);

        $remoteControl->setCommand(0,$partyOnMacro, $partyOffMacro);

        echo $remoteControl->toString();
        echo "--- Pushing Marco On ---<br/>";
        $remoteControl->onButtonWasPushed(0);
        echo "--- Pushing Marco Off ---<br/>";
        $remoteControl->offButtonWasPushed(0);
    }

}